import axios from "axios";
import { message } from "antd";
axios.interceptors.request.use(
  config => {
    config.timeout = 80000;
    return config;
  },
  error => {
    Promise.reject(error);
  }
);

axios.interceptors.response.use(
  res => {
    if (res.data.code === "S0001") {
      return res.data.bizContent;
    } else {
      message.error(res.data.message);
      return Promise.reject(res.data);
    }
  },
  error => {
    const { response } = error;
    if (response) {
      message.error(response.data.message);
    }
    return Promise.reject(error);
  }
);

const request = (options = {}) => axios(options);

export default request;
